package com.example.mylibrary;

import static android.content.ContentValues.TAG;

import android.app.Instrumentation;
import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class OutPage {
    public static Instrumentation instrumentation=null;
    public static UiDevice device=null;
    @Before
    public void initInstrumentation() throws InterruptedException {
        Log.i(TAG,"连接设备");
        instrumentation=
                InstrumentationRegistry.getInstrumentation();
        device=UiDevice.getInstance(instrumentation);
        device.pressHome();
        Thread.sleep(1000);
        UiObject2 icon1=device.findObject
                (By.text("CashBook"));
        icon1.click();
        Thread.sleep(3000);
    }

    //    登录
    private void Login() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_account")).setText("Lizeyu");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_psw")).setText("1");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/login")).click();
    }

    //   支出话费（计数器功能）
    @Test
    public void testOutone() throws InterruptedException {

        Login();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.TextView")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/ll_hf")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("三月份话费");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   支出购物（计数器功能）
    @Test
    public void testOuttwo() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.TextView")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/ll_gw")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_3")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_4")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   支出吃饭（计数器功能）
    @Test
    public void testOutthree() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.TextView")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_cf")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_reset")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_4")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_dot")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   支出其他（计数器功能）
    @Test
    public void testOutfour() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.TextView")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_qt")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("生活用品费用");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_delete")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_7")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    public void testOutfive() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.TextView")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_qt")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }
    public void testOutsix() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.TextView")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_cf")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }
    public void testOutseven() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.TextView")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_gw")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }
    public void testOuteight() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.TextView")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_hf")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //    查看图表数据
    @Test
    public void testTable() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/tb")).click();
    }

    @Test
//添加多个大金额的收入，一个小金额的支出-查看图表
    public void testSix() throws InterruptedException {
        testOutone();
        testOuttwo();
        testOutthree();
        testOutfive();
        testTable();
    }

    @Test
//添加多个不同名不同价的支出账目-查看图表
    public void testSeven() throws InterruptedException {
        testOutone();
        testOuttwo();
        testOutthree();
        testOutfour();
        testTable();
    }

    @Test
//添加多个不同名同价的支出账目-查看图表
    public void testEight() throws InterruptedException {
        testOutfive();
        testOutsix();
        testOutseven();
        testOuteight();
        testTable();
    }

    @Test
//添加多个同名不同价的支出账目-查看图表
    public void testNine() throws InterruptedException {
        testOuteight();
        testOutone();
        testTable();
    }

    @Test
//添加多个同名同价的支出账目-查看图表
    public void testTen() throws InterruptedException {
        testOutone();
        testOutone();
        testOutone();
        testTable();
    }




    @After
    public  void quite(){

        device.pressBack();
    }
}
